<%@page import="merlin.managers.ReportTitlesManager"%>
<%@page import="merlin.managers.WebsiteEnquiriesManager"%>
<%@page import="merlin.beans.ReportTitlesBean"%>
<%@page import="merlin.utils.MerlinUtilities"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>



<%
		
	String grp = request.getParameter("grp");
	String kw = request.getParameter("kw");
	
	if(! MerlinUtilities.isInteger(grp) || MerlinUtilities.isEmpty(kw)){
		out.println("<h3>Invalid parameters</h3>");
		return;
	}

	int reportNumber = Integer.parseInt(grp);
	String companyNumber = kw;
	
	// Store the page visit details.
	WebsiteEnquiriesManager.storeLandingPageVisitDetailsFromEmailLink(reportNumber, companyNumber);
	
	// Get the report details.
	ReportTitlesBean report = ReportTitlesManager.selectReportTitlesByPK(new ReportTitlesBean(reportNumber));
	
%>
	

	
<html>
	<head>
		<meta charset="utf-8"/>
		<meta content="IE=edge, chrome=1" http-equiv="X-UA-Compatible"/>
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		
		<!-- Bootstrap CSS -->
		<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
		<link href="includes/css/bootstrap-glyphicons.css" rel="stylesheet">
		
		<!-- Custom CSS -->
		<link rel="stylesheet" href="includes/css/styles.css">
			
		<!-- Include Modernizr in the head, before any other Javascript -->
		<script src="includes/js/modernizr-2.6.2.min.js"></script>
		
		<!-- Bootstrap JS -->
		<script src="bootstrap/js/bootstrap.min.js"></script>

		<!-- begin DWR imports -->
		<script type='text/javascript' src='dwr/interface/WebsiteEnquiriesManager.js'></script>
		<script type='text/javascript' src='dwr/engine.js'></script>
		<script type='text/javascript' src='dwr/util.js'></script>
		<!-- ends DWR imports -->
	
		<!-- begin jQuery import -->
		<script type='text/javascript' src='mr_scripts/jquery.js'></script>
		<!-- ends jQuery import -->
	
		<script>
			jQuery.noConflict();
		</script>

		<script>
			//validate the format of the e-mail address
			function isValidEMailFormat(aEMailAddress){
			    var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
			    return re.test(aEMailAddress);
			}

		
			function saveEmailAddress(frm){
				var emailAddress = frm.txtEmailAddress.value;
				var reportNumber = frm.hidReportNumber.value;
				var companyNumber = frm.hidCompanyNumber.value;
				
				// validate email address
				emailAddress = emailAddress.toLowerCase();
				if(! isValidEMailFormat(emailAddress)){
					alert("Email address is invalid.");
					return false;
				}	
				
				// TODO : Display some kind of visual feedback to the user that some background processing is happening.
				 
				
				// Save the data in the database, and generate the email.
				WebsiteEnquiriesManager.storeEmailAddressForFreeMSALReport(emailAddress , reportNumber , companyNumber,
					function(){ //Ajax call return handler.
						document.location="http://www.merlinscottassociates.co.uk/MSAL/MSALFreeReportThanks.jsp?grp=<%=reportNumber%>&kw=<%=companyNumber%>";
					}
				);
				return false;
			}
		</script>
		<% 
			if(report != null) {
				String reportNameUpperCase = report.getReportTitle().toUpperCase();
				String reportNameLowerCase = report.getReportTitle().toLowerCase();
				String reportNameTitleCase = MerlinUtilities.capitalizeFully(report.getReportTitle());
		%>
		<title>Free <%=reportNameTitleCase%> Report from Merlin Scott</title>
		<%
				} else {
					out.println("<h3>No report found !</h3>");
				}
		%>
	</head>
	<body>
		<div class="container">
			<div class="container">
				<div class="navbar navbar-fixed-top">
					<div class="navbar-custom">
						<div class="container">
							<a class="navbar-brand" href="#"><img class="img-responsive" src="images/Merlin.png" alt="Merlin Scott  Logo"></img></a>
						</div><!--end container-->
					</div><!--end navbar-inner-->
				</div><!--end navbar-->
			</div>
		
		<% 
			if(report != null) {
				String reportNameUpperCase = report.getReportTitle().toUpperCase();
				String reportNameLowerCase = report.getReportTitle().toLowerCase();
				String reportNameTitleCase = MerlinUtilities.capitalizeFully(report.getReportTitle());
		%>
			<div class="container">
				<div class="row">
					<div class="col-12">
						<div class="header centered">
							<h2>Free Report: Discover 7 of the best firms to own in the <%=reportNameUpperCase %> Sector...</br><small>(FREE analysis of their latest figures)</small></h2>
						</div><!--end header-->
					</div><!--end col-12-->
				</div><!--end row-->
				<div class="row">
					<div class="col-12">
						<div class="centered">
							<h4><span style="color:green" "font-style:italic">Instant Access Now</span></h4>
						</div><!--end header-->
					</div><!--end col-12-->
				</div><!--end row-->
			</div><!--end container-->
											
			<div class="container" id="message">						
				<div class="row">
					<div class="col-12  message">
						<p>In this report you will see the latest figures and analysis of 7 of the best firms to own in the <%=reportNameTitleCase %> sector.</p>
						<p>Join in and receive INSTANT FREE ACCESS - nothing to buy!</p>
						<p>We have analysed and ranked all the <%=report.getNoOfCompaniesInDatabase() %> firms in the latest Merlin Scott Associates full report on the <%=reportNameTitleCase %> sector.  The FREE report shows 7 of the best firms to own and is an example of just what a Merlin Scott Associates Report looks like and what you can do with the searchable database version of the full industry report.</p>
						<p>There is NO COST simply enter your email address below to get instant access to the FREE report.</p>
					</div><!--end col-12-->
				</div><!--end row message-->						
				<div id="divEmailForm">
					<form name="frmReport">
						<input type="hidden" name="hidReportNumber" value = "<%=reportNumber %>"/>
						<input type="hidden" name="hidCompanyNumber" value = "<%=companyNumber %>"/>
						<div class="row">
							<div class="col-12">
								<div class="centered">
									<span style="color:red">*</span> Email Address: <input type="text" name="txtEmailAddress" id="text"/>
								</div><!--end centered-->
							</div><!--end col-12-->
						</div><!--end row-->
						<div class="row">
							<div class="col-12">
								<p id="smallprint"><span style="color:red">*</span> indicates a required field</p>
								<p id="smallprint">By clicking the "Get FREE Report Now" button you submit your information to Merlin Scott Associates, who will use it to communicate the link to download the FREE <%=reportNameLowerCase %> sector report and other services</p>
							</div><!--end col-12-->
						</div><!--end row-->
						<div class="row">
							<div class="col-12">	
								<button type="button" class="btn btn-success pull-right" onClick=" return saveEmailAddress(this.form)">Get FREE Report Now!</button>
							</div><!--end col-12-->
						</div><!--end row-->						
					</form>	
				</div><!--end divEmailForm-->
			</div><!--end message-->
										
		<%
			} else {
				out.println("<h3>No report found !</h3>");
			}
		%>
		</div>
		<a title="shopify analytics tool"
		href="http://statcounter.com/shopify/" target="_blank"><img
		src="http://c.statcounter.com/10256009/0/ced2c5f5/1/"
		alt="shopify analytics tool" style="border:none;"></a>
	</body>
</html>